/* 
 * optionsToggle jQuery plugin
 * Version 0.1
 *
 * Copyright 2010, Zuhdil Herry (zuhdil-at-gmail.com)
 * Dual licensed under the MIT or GPL Version 2 licenses.
 */
(function($){
    $.fn.optionsToggle = function() {
        return this.each(function(){
            buildWidget($(this));
        })
    };
    function buildWidget(wrapper) {
        var options = wrapper.find('.optiontoggle-item'),
            triggers = wrapper.find('.optiontoggle-trigger'),
            trigger = wrapper.find('.optiontoggle-trigger:checked');
        options.hide();
        if (trigger.length === 1) {
            toggleOptions(options, '.'+trigger.val());
        }
        triggers.click(function(){
            trigger = $(this);
            toggleOptions(options, '.'+trigger.val());
        });
    }
    function toggleOptions(opts, target) {
        opts.each(function(){
            var option = $(this);
            if (option.is(target)) {
                option.show();
            } else {
                option.hide();
            }
        });
    }
})(jQuery);